<template>
	<el-form ref="formRef" :model="formData" label-width="150px">
		<el-form-item label="默认渠道：">
			<el-radio-group v-model="formData.identify">
				<el-radio v-for="item in storageMap" :label="item.identify" :index="item.id" :key="item.id">{{ item.name }}</el-radio>
			</el-radio-group>
		</el-form-item>
	</el-form>
	<footerSubmit>
		<el-button v-auth="'setting/sms/edit'" type="primary" @click="handleSubmit">保存</el-button>
	</footerSubmit>
</template>

<script lang="ts" setup name="messageDefaultEdit">
import { ref, reactive, onMounted } from 'vue';
import { smsLists, smsChange } from '/@/api/setting/sms';
import { messageSuccess } from '/@/utils/message';

const formRef = ref(null);

// 表单数据
const formData = reactive({
	identify: 'aliyun',
});

const storageMap = ref([]);

// 获取数据
const getData = async () => {
	const data = await smsLists({status:1});
	storageMap.value = data;

	for (const key in data) {
		if (data[key]?.is_default && data[key].is_default == 1) {
			formData.identify = data[key].identify;
		}
	}
};

// 保存提交
const handleSubmit = async () => {
	await smsChange({ identify: formData.identify });
	messageSuccess('设置成功');
	getData();
};

onMounted(() => {
	getData();
});
</script>
